{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c67af4b7",
   "metadata": {},
   "source": [
    "# 1. 语音录制\n",
    "\n",
    "* 1. 安装和下载模块：pip install 模块名称\n",
    "> 1. SpeechRecognition\n",
    "> 2. Pyaudio\n",
    "> 3. pydub"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "35be7363",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'speech_recognition'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Input \u001b[1;32mIn [1]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mspeech_recognition\u001b[39;00m\n\u001b[0;32m      2\u001b[0m r \u001b[38;5;241m=\u001b[39m speech_recognition\u001b[38;5;241m.\u001b[39mRecognizer()\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m speech_recognition\u001b[38;5;241m.\u001b[39mMicrophone() \u001b[38;5;28;01mas\u001b[39;00m source:\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'speech_recognition'"
     ]
    }
   ],
   "source": [
    "import speech_recognition\n",
    "r = speech_recognition.Recognizer()\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"16k.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "003718b8",
   "metadata": {},
   "source": [
    "# 2. 语音识别（百度的ASR）auto speech recognition\n",
    "\n",
    "* I/O: 音频文件--> 文本文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ce0a43d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import bdasr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4ab114c0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Request time cost 0.963632\n",
      "{\"corpus_no\":\"7245198500629405287\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"他说他呢？\"],\"sn\":\"636376993121686904229\"}\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'{\"corpus_no\":\"7245198500629405287\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"他说他呢？\"],\"sn\":\"636376993121686904229\"}\\n'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bdasr.asr('16k.wav')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b5694749",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Request time cost 0.389376\n",
      "{\"corpus_no\":\"7245198500696858560\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"他说他呢？\"],\"sn\":\"612307757721686904230\"}\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'他说他呢？'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bdasr_result = eval(bdasr.asr('16k.wav'))['result'][0]\n",
    "bdasr_result"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a46ecc1e",
   "metadata": {},
   "source": [
    "# 3. 自然语言处理（NLP）\n",
    "* I/O: 文本--->文本（文本的生成：文本的理解，文本的处理，文本的生成）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "37b1bfcc",
   "metadata": {},
   "outputs": [],
   "source": [
    "qa = {\n",
    "    \"网络与新媒体专业。\":\"网络与新媒体是一门普通高等学校本科专业，属新闻传播学类专业，学制四年，授予文学学士学位\",\n",
    "    \"你是谁？\":\"我是集美貌和智慧于一体的智能小网同学\",\n",
    "    '你好。':\"你也好，我是智能小新，很高兴为你服务\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "8ecaf2bb",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'openai'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Input \u001b[1;32mIn [12]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mopchat\u001b[39;00m\n",
      "File \u001b[1;32mD:\\python\\api\\API\\课堂笔记\\语音\\opchat.py:1\u001b[0m, in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mopenai\u001b[39;00m\n\u001b[0;32m      2\u001b[0m \u001b[38;5;66;03m#主循环\u001b[39;00m\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mopenai_chat\u001b[39m(question):\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'openai'"
     ]
    }
   ],
   "source": [
    "import opchat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0ffff611",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: urllib3==1.25.11 in c:\\users\\asus\\appdata\\local\\programs\\python\\python310\\lib\\site-packages (1.25.11)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "[notice] A new release of pip available: 22.2.1 -> 23.1.2\n",
      "[notice] To update, run: python.exe -m pip install --upgrade pip\n"
     ]
    }
   ],
   "source": [
    "!pip install -U urllib3==1.25.11\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "90c03bba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# packages in environment at C:\\Users\\ASUS\\anaconda3:\n",
      "#\n",
      "# Name                    Version                   Build  Channel\n",
      "_ipyw_jlab_nb_ext_conf    0.1.0            py39haa95532_0  \n",
      "aiohttp                   3.8.1            py39h2bbff1b_1  \n",
      "aiosignal                 1.2.0              pyhd3eb1b0_0  \n",
      "alabaster                 0.7.12             pyhd3eb1b0_0  \n",
      "anaconda                  2022.05                  py39_0  \n",
      "anaconda-client           1.9.0            py39haa95532_0  \n",
      "anaconda-navigator        2.2.0            py39haa95532_0  \n",
      "anaconda-project          0.10.2             pyhd3eb1b0_0  \n",
      "anyio                     3.5.0            py39haa95532_0  \n",
      "appdirs                   1.4.4              pyhd3eb1b0_0  \n",
      "argon2-cffi               21.3.0             pyhd3eb1b0_0  \n",
      "argon2-cffi-bindings      21.2.0           py39h2bbff1b_0  \n",
      "arrow                     1.2.2              pyhd3eb1b0_0  \n",
      "astroid                   2.6.6            py39haa95532_0  \n",
      "astropy                   5.0.4            py39h080aedc_0  \n",
      "asttokens                 2.0.5              pyhd3eb1b0_0  \n",
      "async-timeout             4.0.1              pyhd3eb1b0_0  \n",
      "atomicwrites              1.4.0                      py_0  \n",
      "attrs                     21.4.0             pyhd3eb1b0_0  \n",
      "automat                   20.2.0                     py_0  \n",
      "autopep8                  1.6.0              pyhd3eb1b0_0  \n",
      "babel                     2.9.1              pyhd3eb1b0_0  \n",
      "backcall                  0.2.0              pyhd3eb1b0_0  \n",
      "backports                 1.1                pyhd3eb1b0_0  \n",
      "backports.functools_lru_cache 1.6.4              pyhd3eb1b0_0  \n",
      "backports.tempfile        1.0                pyhd3eb1b0_1  \n",
      "backports.weakref         1.0.post1                  py_1  \n",
      "bcrypt                    3.2.0            py39h196d8e1_0  \n",
      "beautifulsoup4            4.11.1           py39haa95532_0  \n",
      "binaryornot               0.4.4              pyhd3eb1b0_1  \n",
      "bitarray                  2.4.1            py39h2bbff1b_0  \n",
      "bkcharts                  0.2              py39haa95532_0  \n",
      "black                     19.10b0                    py_0  \n",
      "blas                      1.0                         mkl  \n",
      "bleach                    4.1.0              pyhd3eb1b0_0  \n",
      "blosc                     1.21.0               h19a0ad4_0  \n",
      "bokeh                     2.4.2            py39haa95532_0  \n",
      "boto3                     1.21.32            pyhd3eb1b0_0  \n",
      "botocore                  1.24.32            pyhd3eb1b0_0  \n",
      "bottleneck                1.3.4            py39h080aedc_0  \n",
      "brotli                    1.0.9                ha925a31_2  \n",
      "brotlipy                  0.7.0           py39h2bbff1b_1003  \n",
      "bzip2                     1.0.8                he774522_0  \n",
      "ca-certificates           2022.3.29            haa95532_1  \n",
      "cachetools                4.2.2              pyhd3eb1b0_0  \n",
      "certifi                   2021.10.8        py39haa95532_2  \n",
      "cffi                      1.15.0           py39h2bbff1b_1  \n",
      "cfitsio                   3.470                he774522_6  \n",
      "chardet                   4.0.0           py39haa95532_1003  \n",
      "charls                    2.2.0                h6c2663c_0  \n",
      "charset-normalizer        2.0.4              pyhd3eb1b0_0  \n",
      "click                     8.0.4            py39haa95532_0  \n",
      "cloudpickle               2.0.0              pyhd3eb1b0_0  \n",
      "clyent                    1.2.2            py39haa95532_1  \n",
      "colorama                  0.4.4              pyhd3eb1b0_0  \n",
      "colorcet                  2.0.6              pyhd3eb1b0_0  \n",
      "comtypes                  1.1.10          py39haa95532_1002  \n",
      "conda                     4.14.0           py39haa95532_0  \n",
      "conda-build               3.21.8           py39haa95532_2  \n",
      "conda-content-trust       0.1.1              pyhd3eb1b0_0  \n",
      "conda-env                 2.6.0                haa95532_1  \n",
      "conda-pack                0.6.0              pyhd3eb1b0_0  \n",
      "conda-package-handling    1.8.1            py39h8cc25b3_0  \n",
      "conda-repo-cli            1.0.4              pyhd3eb1b0_0  \n",
      "conda-token               0.3.0              pyhd3eb1b0_0  \n",
      "conda-verify              3.4.2                      py_1  \n",
      "console_shortcut          0.1.1                         4  \n",
      "constantly                15.1.0             pyh2b92418_0  \n",
      "cookiecutter              1.7.3              pyhd3eb1b0_0  \n",
      "cryptography              3.4.8            py39h71e12ea_0  \n",
      "cssselect                 1.1.0              pyhd3eb1b0_0  \n",
      "curl                      7.82.0               h2bbff1b_0  \n",
      "cycler                    0.11.0             pyhd3eb1b0_0  \n",
      "cython                    0.29.28          py39hd77b12b_0  \n",
      "cytoolz                   0.11.0           py39h2bbff1b_0  \n",
      "daal4py                   2021.5.0         py39h8cb3d55_0  \n",
      "dal                       2021.5.0           haa95532_796  \n",
      "dask                      2022.2.1           pyhd3eb1b0_0  \n",
      "dask-core                 2022.2.1           pyhd3eb1b0_0  \n",
      "dataclasses               0.8                pyh6d0b6a4_7  \n",
      "datashader                0.13.0             pyhd3eb1b0_1  \n",
      "datashape                 0.5.4            py39haa95532_1  \n",
      "debugpy                   1.5.1            py39hd77b12b_0  \n",
      "decorator                 5.1.1              pyhd3eb1b0_0  \n",
      "defusedxml                0.7.1              pyhd3eb1b0_0  \n",
      "diff-match-patch          20200713           pyhd3eb1b0_0  \n",
      "distributed               2022.2.1           pyhd3eb1b0_0  \n",
      "docutils                  0.17.1           py39haa95532_1  \n",
      "entrypoints               0.4              py39haa95532_0  \n",
      "et_xmlfile                1.1.0            py39haa95532_0  \n",
      "executing                 0.8.3              pyhd3eb1b0_0  \n",
      "filelock                  3.6.0              pyhd3eb1b0_0  \n",
      "flake8                    3.9.2              pyhd3eb1b0_0  \n",
      "flask                     1.1.2              pyhd3eb1b0_0  \n",
      "fonttools                 4.25.0             pyhd3eb1b0_0  \n",
      "freetype                  2.10.4               hd328e21_0  \n",
      "frozenlist                1.2.0            py39h2bbff1b_0  \n",
      "fsspec                    2022.2.0           pyhd3eb1b0_0  \n",
      "future                    0.18.2           py39haa95532_1  \n",
      "gensim                    4.1.2            py39hd77b12b_0  \n",
      "giflib                    5.2.1                h62dcd97_0  \n",
      "glob2                     0.7                pyhd3eb1b0_0  \n",
      "google-api-core           1.25.1             pyhd3eb1b0_0  \n",
      "google-auth               1.33.0             pyhd3eb1b0_0  \n",
      "google-cloud-core         1.7.1              pyhd3eb1b0_0  \n",
      "google-cloud-storage      1.31.0                     py_0  \n",
      "google-crc32c             1.1.2            py39h2bbff1b_0  \n",
      "google-resumable-media    1.3.1              pyhd3eb1b0_1  \n",
      "googleapis-common-protos  1.53.0           py39h2eaa2aa_0  \n",
      "greenlet                  1.1.1            py39hd77b12b_0  \n",
      "grpcio                    1.42.0           py39hc60d5dd_0  \n",
      "h5py                      3.6.0            py39h3de5c98_0  \n",
      "hdf5                      1.10.6               h7ebc959_0  \n",
      "heapdict                  1.0.1              pyhd3eb1b0_0  \n",
      "holoviews                 1.14.8             pyhd3eb1b0_0  \n",
      "hvplot                    0.7.3              pyhd3eb1b0_1  \n",
      "hyperlink                 21.0.0             pyhd3eb1b0_0  \n",
      "icc_rt                    2019.0.0             h0cc432a_1  \n",
      "icu                       58.2                 ha925a31_3  \n",
      "idna                      3.3                pyhd3eb1b0_0  \n",
      "imagecodecs               2021.8.26        py39ha1f97ea_0  \n",
      "imageio                   2.9.0              pyhd3eb1b0_0  \n",
      "imagesize                 1.3.0              pyhd3eb1b0_0  \n",
      "importlib-metadata        4.11.3           py39haa95532_0  \n",
      "importlib_metadata        4.11.3               hd3eb1b0_0  \n",
      "incremental               21.3.0             pyhd3eb1b0_0  \n",
      "inflection                0.5.1            py39haa95532_0  \n",
      "iniconfig                 1.1.1              pyhd3eb1b0_0  \n",
      "intake                    0.6.5              pyhd3eb1b0_0  \n",
      "intel-openmp              2021.4.0          haa95532_3556  \n",
      "intervaltree              3.1.0              pyhd3eb1b0_0  \n",
      "ipykernel                 6.9.1            py39haa95532_0  \n",
      "ipython                   8.2.0            py39haa95532_0  \n",
      "ipython_genutils          0.2.0              pyhd3eb1b0_1  \n",
      "ipywidgets                7.6.5              pyhd3eb1b0_1  \n",
      "isort                     5.9.3              pyhd3eb1b0_0  \n",
      "itemadapter               0.3.0              pyhd3eb1b0_0  \n",
      "itemloaders               1.0.4              pyhd3eb1b0_1  \n",
      "itsdangerous              2.0.1              pyhd3eb1b0_0  \n",
      "jdcal                     1.4.1              pyhd3eb1b0_0  \n",
      "jedi                      0.18.1           py39haa95532_1  \n",
      "jinja2                    2.11.3             pyhd3eb1b0_0  \n",
      "jinja2-time               0.2.0              pyhd3eb1b0_3  \n",
      "jmespath                  0.10.0             pyhd3eb1b0_0  \n",
      "joblib                    1.1.0              pyhd3eb1b0_0  \n",
      "jpeg                      9e                   h2bbff1b_0  \n",
      "jq                        1.6                  haa95532_1  \n",
      "json5                     0.9.6              pyhd3eb1b0_0  \n",
      "jsonschema                4.4.0            py39haa95532_0  \n",
      "jupyter                   1.0.0            py39haa95532_7  \n",
      "jupyter_client            6.1.12             pyhd3eb1b0_0  \n",
      "jupyter_console           6.4.0              pyhd3eb1b0_0  \n",
      "jupyter_core              4.9.2            py39haa95532_0  \n",
      "jupyter_server            1.13.5             pyhd3eb1b0_0  \n",
      "jupyterlab                3.3.2              pyhd3eb1b0_0  \n",
      "jupyterlab_pygments       0.1.2                      py_0  \n",
      "jupyterlab_server         2.10.3             pyhd3eb1b0_1  \n",
      "jupyterlab_widgets        1.0.0              pyhd3eb1b0_1  \n",
      "keyring                   23.4.0           py39haa95532_0  \n",
      "kiwisolver                1.3.2            py39hd77b12b_0  \n",
      "lazy-object-proxy         1.6.0            py39h2bbff1b_0  \n",
      "lcms2                     2.12                 h83e58a3_0  \n",
      "lerc                      3.0                  hd77b12b_0  \n",
      "libaec                    1.0.4                h33f27b4_1  \n",
      "libarchive                3.4.2                h5e25573_0  \n",
      "libcrc32c                 1.1.1                ha925a31_2  \n",
      "libcurl                   7.82.0               h86230a5_0  \n",
      "libdeflate                1.8                  h2bbff1b_5  \n",
      "libiconv                  1.16                 h2bbff1b_2  \n",
      "liblief                   0.11.5               hd77b12b_1  \n",
      "libpng                    1.6.37               h2a8f88b_0  \n",
      "libprotobuf               3.19.1               h23ce68f_0  \n",
      "libspatialindex           1.9.3                h6c2663c_0  \n",
      "libssh2                   1.10.0               hcd4344a_0  \n",
      "libtiff                   4.2.0                hd0e1b90_0  \n",
      "libwebp                   1.2.2                h2bbff1b_0  \n",
      "libxml2                   2.9.12               h0ad7f3c_0  \n",
      "libxslt                   1.1.34               he774522_0  \n",
      "libzopfli                 1.0.3                ha925a31_0  \n",
      "llvmlite                  0.38.0           py39h23ce68f_0  \n",
      "locket                    0.2.1            py39haa95532_2  \n",
      "lxml                      4.8.0            py39h1985fb9_0  \n",
      "lz4-c                     1.9.3                h2bbff1b_1  \n",
      "lzo                       2.10                 he774522_2  \n",
      "m2w64-libwinpthread-git   5.0.0.4634.697f757               2  \n",
      "markdown                  3.3.4            py39haa95532_0  \n",
      "markupsafe                2.0.1            py39h2bbff1b_0  \n",
      "matplotlib                3.5.1            py39haa95532_1  \n",
      "matplotlib-base           3.5.1            py39hd77b12b_1  \n",
      "matplotlib-inline         0.1.2              pyhd3eb1b0_2  \n",
      "mccabe                    0.6.1            py39haa95532_1  \n",
      "menuinst                  1.4.18           py39h59b6b97_0  \n",
      "mistune                   0.8.4           py39h2bbff1b_1000  \n",
      "mkl                       2021.4.0           haa95532_640  \n",
      "mkl-service               2.4.0            py39h2bbff1b_0  \n",
      "mkl_fft                   1.3.1            py39h277e83a_0  \n",
      "mkl_random                1.2.2            py39hf11a4ad_0  \n",
      "mock                      4.0.3              pyhd3eb1b0_0  \n",
      "mpmath                    1.2.1            py39haa95532_0  \n",
      "msgpack-python            1.0.2            py39h59b6b97_1  \n",
      "msys2-conda-epoch         20160418                      1  \n",
      "multidict                 5.1.0            py39h2bbff1b_2  \n",
      "multipledispatch          0.6.0            py39haa95532_0  \n",
      "munkres                   1.1.4                      py_0  \n",
      "mypy_extensions           0.4.3            py39haa95532_1  \n",
      "navigator-updater         0.2.1                    py39_1  \n",
      "nbclassic                 0.3.5              pyhd3eb1b0_0  \n",
      "nbclient                  0.5.13           py39haa95532_0  \n",
      "nbconvert                 6.4.4            py39haa95532_0  \n",
      "nbformat                  5.3.0            py39haa95532_0  \n",
      "nest-asyncio              1.5.5            py39haa95532_0  \n",
      "networkx                  2.7.1              pyhd3eb1b0_0  \n",
      "nltk                      3.7                pyhd3eb1b0_0  \n",
      "nose                      1.3.7           pyhd3eb1b0_1008  \n",
      "notebook                  6.4.8            py39haa95532_0  \n",
      "numba                     0.55.1           py39hf11a4ad_0  \n",
      "numexpr                   2.8.1            py39hb80d3ca_0  \n",
      "numpy                     1.21.5           py39h7a0a035_1  \n",
      "numpy-base                1.21.5           py39hca35cd5_1  \n",
      "numpydoc                  1.2                pyhd3eb1b0_0  \n",
      "olefile                   0.46               pyhd3eb1b0_0  \n",
      "openjpeg                  2.4.0                h4fc8c34_0  \n",
      "openpyxl                  3.0.9              pyhd3eb1b0_0  \n",
      "openssl                   1.1.1n               h2bbff1b_0  \n",
      "packaging                 21.3               pyhd3eb1b0_0  \n",
      "pandas                    1.4.2            py39hd77b12b_0  \n",
      "pandocfilters             1.5.0              pyhd3eb1b0_0  \n",
      "panel                     0.13.0           py39haa95532_0  \n",
      "param                     1.12.0             pyhd3eb1b0_0  \n",
      "paramiko                  2.8.1              pyhd3eb1b0_0  \n",
      "parsel                    1.6.0            py39haa95532_0  \n",
      "parso                     0.8.3              pyhd3eb1b0_0  \n",
      "partd                     1.2.0              pyhd3eb1b0_1  \n",
      "pathspec                  0.7.0                      py_0  \n",
      "patsy                     0.5.2            py39haa95532_1  \n",
      "pep8                      1.7.1            py39haa95532_0  \n",
      "pexpect                   4.8.0              pyhd3eb1b0_3  \n",
      "pickleshare               0.7.5           pyhd3eb1b0_1003  \n",
      "pillow                    9.0.1            py39hdc2b20a_0  \n",
      "pip                       21.2.4           py39haa95532_0  \n",
      "pkginfo                   1.8.2              pyhd3eb1b0_0  \n",
      "plotly                    5.6.0              pyhd3eb1b0_0  \n",
      "pluggy                    1.0.0            py39haa95532_1  \n",
      "powershell_shortcut       0.0.1                         3  \n",
      "poyo                      0.5.0              pyhd3eb1b0_0  \n",
      "prometheus_client         0.13.1             pyhd3eb1b0_0  \n",
      "prompt-toolkit            3.0.20             pyhd3eb1b0_0  \n",
      "prompt_toolkit            3.0.20               hd3eb1b0_0  \n",
      "protego                   0.1.16                     py_0  \n",
      "protobuf                  3.19.1           py39hd77b12b_0  \n",
      "psutil                    5.8.0            py39h2bbff1b_1  \n",
      "ptyprocess                0.7.0              pyhd3eb1b0_2  \n",
      "pure_eval                 0.2.2              pyhd3eb1b0_0  \n",
      "py                        1.11.0             pyhd3eb1b0_0  \n",
      "py-lief                   0.11.5           py39hd77b12b_1  \n",
      "pyasn1                    0.4.8              pyhd3eb1b0_0  \n",
      "pyasn1-modules            0.2.8                      py_0  \n",
      "pycodestyle               2.7.0              pyhd3eb1b0_0  \n",
      "pycosat                   0.6.3            py39h2bbff1b_0  \n",
      "pycparser                 2.21               pyhd3eb1b0_0  \n",
      "pyct                      0.4.6            py39haa95532_0  \n",
      "pycurl                    7.44.1           py39hcd4344a_1  \n",
      "pydispatcher              2.0.5            py39haa95532_2  \n",
      "pydocstyle                6.1.1              pyhd3eb1b0_0  \n",
      "pyerfa                    2.0.0            py39h2bbff1b_0  \n",
      "pyflakes                  2.3.1              pyhd3eb1b0_0  \n",
      "pygments                  2.11.2             pyhd3eb1b0_0  \n",
      "pyhamcrest                2.0.2              pyhd3eb1b0_2  \n",
      "pyjwt                     2.1.0            py39haa95532_0  \n",
      "pylint                    2.9.6            py39haa95532_1  \n",
      "pyls-spyder               0.4.0              pyhd3eb1b0_0  \n",
      "pynacl                    1.4.0            py39hbd8134f_1  \n",
      "pyodbc                    4.0.32           py39hd77b12b_1  \n",
      "pyopenssl                 21.0.0             pyhd3eb1b0_1  \n",
      "pyparsing                 3.0.4              pyhd3eb1b0_0  \n",
      "pyqt                      5.9.2            py39hd77b12b_6  \n",
      "pyreadline                2.1              py39haa95532_1  \n",
      "pyrsistent                0.18.0           py39h196d8e1_0  \n",
      "pysocks                   1.7.1            py39haa95532_0  \n",
      "pytables                  3.6.1            py39h56d22b6_1  \n",
      "pytest                    7.1.1            py39haa95532_0  \n",
      "python                    3.9.12               h6244533_0  \n",
      "python-dateutil           2.8.2              pyhd3eb1b0_0  \n",
      "python-fastjsonschema     2.15.1             pyhd3eb1b0_0  \n",
      "python-libarchive-c       2.9                pyhd3eb1b0_1  \n",
      "python-lsp-black          1.0.0              pyhd3eb1b0_0  \n",
      "python-lsp-jsonrpc        1.0.0              pyhd3eb1b0_0  \n",
      "python-lsp-server         1.2.4              pyhd3eb1b0_0  \n",
      "python-slugify            5.0.2              pyhd3eb1b0_0  \n",
      "python-snappy             0.6.0            py39hd77b12b_3  \n",
      "pytz                      2021.3             pyhd3eb1b0_0  \n",
      "pyviz_comms               2.0.2              pyhd3eb1b0_0  \n",
      "pywavelets                1.3.0            py39h2bbff1b_0  \n",
      "pywin32                   302              py39h2bbff1b_2  \n",
      "pywin32-ctypes            0.2.0           py39haa95532_1000  \n",
      "pywinpty                  2.0.2            py39h5da7b33_0  \n",
      "pyyaml                    6.0              py39h2bbff1b_1  \n",
      "pyzmq                     22.3.0           py39hd77b12b_2  \n",
      "qdarkstyle                3.0.2              pyhd3eb1b0_0  \n",
      "qstylizer                 0.1.10             pyhd3eb1b0_0  \n",
      "qt                        5.9.7            vc14h73c81de_0  \n",
      "qtawesome                 1.0.3              pyhd3eb1b0_0  \n",
      "qtconsole                 5.3.0              pyhd3eb1b0_0  \n",
      "qtpy                      2.0.1              pyhd3eb1b0_0  \n",
      "queuelib                  1.5.0            py39haa95532_0  \n",
      "regex                     2022.3.15        py39h2bbff1b_0  \n",
      "requests                  2.27.1             pyhd3eb1b0_0  \n",
      "requests-file             1.5.1              pyhd3eb1b0_0  \n",
      "rope                      0.22.0             pyhd3eb1b0_0  \n",
      "rsa                       4.7.2              pyhd3eb1b0_1  \n",
      "rtree                     0.9.7            py39h2eaa2aa_1  \n",
      "ruamel_yaml               0.15.100         py39h2bbff1b_0  \n",
      "s3transfer                0.5.0              pyhd3eb1b0_0  \n",
      "scikit-image              0.19.2           py39hf11a4ad_0  \n",
      "scikit-learn              1.0.2            py39hf11a4ad_1  \n",
      "scikit-learn-intelex      2021.5.0         py39haa95532_0  \n",
      "scipy                     1.7.3            py39h0a974cb_0  \n",
      "scrapy                    2.6.1            py39haa95532_0  \n",
      "seaborn                   0.11.2             pyhd3eb1b0_0  \n",
      "send2trash                1.8.0              pyhd3eb1b0_1  \n",
      "service_identity          18.1.0             pyhd3eb1b0_1  \n",
      "setuptools                61.2.0           py39haa95532_0  \n",
      "sip                       4.19.13          py39hd77b12b_0  \n",
      "six                       1.16.0             pyhd3eb1b0_1  \n",
      "smart_open                5.1.0              pyhd3eb1b0_0  \n",
      "snappy                    1.1.9                h6c2663c_0  \n",
      "sniffio                   1.2.0            py39haa95532_1  \n",
      "snowballstemmer           2.2.0              pyhd3eb1b0_0  \n",
      "sortedcollections         2.1.0              pyhd3eb1b0_0  \n",
      "sortedcontainers          2.4.0              pyhd3eb1b0_0  \n",
      "soupsieve                 2.3.1              pyhd3eb1b0_0  \n",
      "sphinx                    4.4.0              pyhd3eb1b0_0  \n",
      "sphinxcontrib-applehelp   1.0.2              pyhd3eb1b0_0  \n",
      "sphinxcontrib-devhelp     1.0.2              pyhd3eb1b0_0  \n",
      "sphinxcontrib-htmlhelp    2.0.0              pyhd3eb1b0_0  \n",
      "sphinxcontrib-jsmath      1.0.1              pyhd3eb1b0_0  \n",
      "sphinxcontrib-qthelp      1.0.3              pyhd3eb1b0_0  \n",
      "sphinxcontrib-serializinghtml 1.1.5              pyhd3eb1b0_0  \n",
      "spyder                    5.1.5            py39haa95532_1  \n",
      "spyder-kernels            2.1.3            py39haa95532_0  \n",
      "sqlalchemy                1.4.32           py39h2bbff1b_0  \n"
     ]
    }
   ],
   "source": [
    "!conda list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "baca1d24",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'opchat' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [13]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mopchat\u001b[49m\u001b[38;5;241m.\u001b[39mopenai_chat(bdasr_result)\n\u001b[0;32m      2\u001b[0m result\n",
      "\u001b[1;31mNameError\u001b[0m: name 'opchat' is not defined"
     ]
    }
   ],
   "source": [
    "result = opchat.openai_chat(bdasr_result)\n",
    "result"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e549c310",
   "metadata": {},
   "source": [
    "# 4. 语音合成（百度的TTS）text to speech\n",
    "* I/O：文本文件--> 音频文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "72ca52f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import bdtts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a8301749",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'result' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [10]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m bdtts\u001b[38;5;241m.\u001b[39mtts(\u001b[43mresult\u001b[49m)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'result' is not defined"
     ]
    }
   ],
   "source": [
    "bdtts.tts(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "939251e2",
   "metadata": {},
   "source": [
    "# 5. 播放语音合成的音频"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b57859a3",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pydub'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Input \u001b[1;32mIn [11]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpydub\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m AudioSegment\n\u001b[0;32m      2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpydub\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mplayback\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m play\n\u001b[0;32m      3\u001b[0m song \u001b[38;5;241m=\u001b[39m AudioSegment\u001b[38;5;241m.\u001b[39mfrom_wav(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mresult.wav\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'pydub'"
     ]
    }
   ],
   "source": [
    "from pydub import AudioSegment\n",
    "from pydub.playback import play\n",
    "song = AudioSegment.from_wav('result.wav')\n",
    "play(song)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8be6c5ce",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34f659bd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
